﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Einstein.Data; 
using Einstein.Utility;
using DevComponents.DotNetBar;
using Einstein.Group.DAL;

namespace Einstein.Platform.Window.Basic
{
    public partial class Basic_UserType_New : Office2007Form
    {
        public Basic_UserType_New()
        {
            InitializeComponent();

        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (superValidator1.Validate())
            {
                UserTypeInfoDAL dal = new UserTypeInfoDAL();
                UserTypeInfo info = new UserTypeInfo { UserTypeName = txtUserType.Text, Desc = txtDesc.Text };
                bool isEdit = false;
                if (this.UserTypeInfo != null)
                {
                    info.UserTypeID = this.UserTypeInfo.UserTypeID;
                    isEdit = true;
                }
                if (dal.Exist(info))
                {
                    BoxManager.ShowWarning("已经存在相同的用户类型，请重试。");
                    return;
                }
                bool result = isEdit ? dal.Update(info) : dal.Add(info);
                if (result)
                {
                    BoxManager.ShowSuccess();
                }
                else
                {
                    BoxManager.ShowFail();
                }

                this.DialogResult = DialogResult.OK;
            }
        }

        public UserTypeInfo UserTypeInfo
        {
            get;
            set;
        }

        public void BindData()
        {
            if (UserTypeInfo != null)
            {
                txtUserType.Text = UserTypeInfo.UserTypeName;
                txtDesc.Text = UserTypeInfo.Desc;
            }
        }
    }
}
